package com.da.javatest.leetCode;

/**
 * @author chenlida
 * @date 2019/3/1 15:29
 * @description
 */
public class Code724 {
    public static void main(String[] args) {
        System.out.println(new Code724().pivotIndex(new int[] {-1, -1, -1, -1, -1}));

    }

    public int pivotIndex(int[] nums) {
        if (nums.length < 3) {
            return -1;
        }
        int sum = 0, left = 0;
        for (int i = 0; i < nums.length; i++) {
            sum += nums[i];
        }
        for (int i = 0; i < nums.length; i++) {
            if ((sum - nums[i]) == left * 2) {
                return i;
            }
            left += nums[i];
        }
        return -1;
    }
}
